/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = 'regional';
  
  checkConfig(config);
  @endpoint = getEndpoint('onsmqtt', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model ApplyTokenRequest {
  actions?: string(name='Actions'),
  expireTime?: long(name='ExpireTime'),
  instanceId?: string(name='InstanceId'),
  resources?: string(name='Resources'),
}

model ApplyTokenResponseBody = {
  requestId?: string(name='RequestId'),
  token?: string(name='Token'),
}

model ApplyTokenResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ApplyTokenResponseBody(name='body'),
}

async function applyTokenWithOptions(request: ApplyTokenRequest, runtime: Util.RuntimeOptions): ApplyTokenResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.actions)) {
    query['Actions'] = request.actions;
  }
  if (!Util.isUnset(request.expireTime)) {
    query['ExpireTime'] = request.expireTime;
  }
  if (!Util.isUnset(request.instanceId)) {
    query['InstanceId'] = request.instanceId;
  }
  if (!Util.isUnset(request.resources)) {
    query['Resources'] = request.resources;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ApplyToken',
    version = '2019-12-11',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function applyToken(request: ApplyTokenRequest): ApplyTokenResponse {
  var runtime = new Util.RuntimeOptions{};
  return applyTokenWithOptions(request, runtime);
}

model BatchQuerySessionByClientIdsRequest {
  clientIdList?: [ string ](name='ClientIdList'),
  instanceId?: string(name='InstanceId'),
}

model BatchQuerySessionByClientIdsResponseBody = {
  onlineStatusList?: [ 
    {
      clientId?: string(name='ClientId'),
      onlineStatus?: boolean(name='OnlineStatus'),
    }
  ](name='OnlineStatusList'),
  requestId?: string(name='RequestId'),
}

model BatchQuerySessionByClientIdsResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: BatchQuerySessionByClientIdsResponseBody(name='body'),
}

async function batchQuerySessionByClientIdsWithOptions(request: BatchQuerySessionByClientIdsRequest, runtime: Util.RuntimeOptions): BatchQuerySessionByClientIdsResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.clientIdList)) {
    query['ClientIdList'] = request.clientIdList;
  }
  if (!Util.isUnset(request.instanceId)) {
    query['InstanceId'] = request.instanceId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'BatchQuerySessionByClientIds',
    version = '2019-12-11',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function batchQuerySessionByClientIds(request: BatchQuerySessionByClientIdsRequest): BatchQuerySessionByClientIdsResponse {
  var runtime = new Util.RuntimeOptions{};
  return batchQuerySessionByClientIdsWithOptions(request, runtime);
}

model BatchSendMessagesRequest {
  instanceId?: string(name='InstanceId'),
  messages?: [ 
    {
      id?: int32(name='Id'),
      payload?: string(name='Payload'),
      receiptId?: string(name='ReceiptId'),
      topics?: [ string ](name='Topics'),
    }
  ](name='Messages'),
}

model BatchSendMessagesResponseBody = {
  requestId?: string(name='RequestId'),
  responses?: [ 
    {
      errorCode?: int32(name='ErrorCode'),
      errorMessage?: string(name='ErrorMessage'),
      id?: int32(name='Id'),
      msgId?: string(name='MsgId'),
    }
  ](name='Responses'),
}

model BatchSendMessagesResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: BatchSendMessagesResponseBody(name='body'),
}

async function batchSendMessagesWithOptions(request: BatchSendMessagesRequest, runtime: Util.RuntimeOptions): BatchSendMessagesResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.instanceId)) {
    query['InstanceId'] = request.instanceId;
  }
  if (!Util.isUnset(request.messages)) {
    query['Messages'] = request.messages;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'BatchSendMessages',
    version = '2019-12-11',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function batchSendMessages(request: BatchSendMessagesRequest): BatchSendMessagesResponse {
  var runtime = new Util.RuntimeOptions{};
  return batchSendMessagesWithOptions(request, runtime);
}

model CreateGroupIdRequest {
  groupId?: string(name='GroupId'),
  instanceId?: string(name='InstanceId'),
}

model CreateGroupIdResponseBody = {
  requestId?: string(name='RequestId'),
}

model CreateGroupIdResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: CreateGroupIdResponseBody(name='body'),
}

async function createGroupIdWithOptions(request: CreateGroupIdRequest, runtime: Util.RuntimeOptions): CreateGroupIdResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.groupId)) {
    query['GroupId'] = request.groupId;
  }
  if (!Util.isUnset(request.instanceId)) {
    query['InstanceId'] = request.instanceId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'CreateGroupId',
    version = '2019-12-11',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function createGroupId(request: CreateGroupIdRequest): CreateGroupIdResponse {
  var runtime = new Util.RuntimeOptions{};
  return createGroupIdWithOptions(request, runtime);
}

model DeleteGroupIdRequest {
  groupId?: string(name='GroupId'),
  instanceId?: string(name='InstanceId'),
}

model DeleteGroupIdResponseBody = {
  requestId?: string(name='RequestId'),
}

model DeleteGroupIdResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: DeleteGroupIdResponseBody(name='body'),
}

async function deleteGroupIdWithOptions(request: DeleteGroupIdRequest, runtime: Util.RuntimeOptions): DeleteGroupIdResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.groupId)) {
    query['GroupId'] = request.groupId;
  }
  if (!Util.isUnset(request.instanceId)) {
    query['InstanceId'] = request.instanceId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'DeleteGroupId',
    version = '2019-12-11',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function deleteGroupId(request: DeleteGroupIdRequest): DeleteGroupIdResponse {
  var runtime = new Util.RuntimeOptions{};
  return deleteGroupIdWithOptions(request, runtime);
}

model ListGroupIdRequest {
  instanceId?: string(name='InstanceId'),
}

model ListGroupIdResponseBody = {
  data?: [ 
    {
      createTime?: long(name='CreateTime'),
      groupId?: string(name='GroupId'),
      independentNaming?: boolean(name='IndependentNaming'),
      instanceId?: string(name='InstanceId'),
      updateTime?: long(name='UpdateTime'),
    }
  ](name='Data'),
  requestId?: string(name='RequestId'),
}

model ListGroupIdResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ListGroupIdResponseBody(name='body'),
}

async function listGroupIdWithOptions(request: ListGroupIdRequest, runtime: Util.RuntimeOptions): ListGroupIdResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.instanceId)) {
    query['InstanceId'] = request.instanceId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ListGroupId',
    version = '2019-12-11',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function listGroupId(request: ListGroupIdRequest): ListGroupIdResponse {
  var runtime = new Util.RuntimeOptions{};
  return listGroupIdWithOptions(request, runtime);
}

model QuerySessionByClientIdRequest {
  clientId?: string(name='ClientId'),
  instanceId?: string(name='InstanceId'),
}

model QuerySessionByClientIdResponseBody = {
  onlineStatus?: boolean(name='OnlineStatus'),
  requestId?: string(name='RequestId'),
}

model QuerySessionByClientIdResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: QuerySessionByClientIdResponseBody(name='body'),
}

async function querySessionByClientIdWithOptions(request: QuerySessionByClientIdRequest, runtime: Util.RuntimeOptions): QuerySessionByClientIdResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.clientId)) {
    query['ClientId'] = request.clientId;
  }
  if (!Util.isUnset(request.instanceId)) {
    query['InstanceId'] = request.instanceId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'QuerySessionByClientId',
    version = '2019-12-11',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function querySessionByClientId(request: QuerySessionByClientIdRequest): QuerySessionByClientIdResponse {
  var runtime = new Util.RuntimeOptions{};
  return querySessionByClientIdWithOptions(request, runtime);
}

model QueryTokenRequest {
  instanceId?: string(name='InstanceId'),
  token?: string(name='Token'),
}

model QueryTokenResponseBody = {
  requestId?: string(name='RequestId'),
  tokenStatus?: boolean(name='TokenStatus'),
}

model QueryTokenResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: QueryTokenResponseBody(name='body'),
}

async function queryTokenWithOptions(request: QueryTokenRequest, runtime: Util.RuntimeOptions): QueryTokenResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.instanceId)) {
    query['InstanceId'] = request.instanceId;
  }
  if (!Util.isUnset(request.token)) {
    query['Token'] = request.token;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'QueryToken',
    version = '2019-12-11',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function queryToken(request: QueryTokenRequest): QueryTokenResponse {
  var runtime = new Util.RuntimeOptions{};
  return queryTokenWithOptions(request, runtime);
}

model RevokeTokenRequest {
  instanceId?: string(name='InstanceId'),
  token?: string(name='Token'),
}

model RevokeTokenResponseBody = {
  requestId?: string(name='RequestId'),
}

model RevokeTokenResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: RevokeTokenResponseBody(name='body'),
}

async function revokeTokenWithOptions(request: RevokeTokenRequest, runtime: Util.RuntimeOptions): RevokeTokenResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.instanceId)) {
    query['InstanceId'] = request.instanceId;
  }
  if (!Util.isUnset(request.token)) {
    query['Token'] = request.token;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'RevokeToken',
    version = '2019-12-11',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function revokeToken(request: RevokeTokenRequest): RevokeTokenResponse {
  var runtime = new Util.RuntimeOptions{};
  return revokeTokenWithOptions(request, runtime);
}

model SendMessageRequest {
  instanceId?: string(name='InstanceId'),
  mqttTopic?: string(name='MqttTopic'),
  payload?: string(name='Payload'),
  receiptId?: string(name='ReceiptId'),
}

model SendMessageResponseBody = {
  msgId?: string(name='MsgId'),
  requestId?: string(name='RequestId'),
}

model SendMessageResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SendMessageResponseBody(name='body'),
}

async function sendMessageWithOptions(request: SendMessageRequest, runtime: Util.RuntimeOptions): SendMessageResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.instanceId)) {
    query['InstanceId'] = request.instanceId;
  }
  if (!Util.isUnset(request.mqttTopic)) {
    query['MqttTopic'] = request.mqttTopic;
  }
  if (!Util.isUnset(request.payload)) {
    query['Payload'] = request.payload;
  }
  if (!Util.isUnset(request.receiptId)) {
    query['ReceiptId'] = request.receiptId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'SendMessage',
    version = '2019-12-11',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function sendMessage(request: SendMessageRequest): SendMessageResponse {
  var runtime = new Util.RuntimeOptions{};
  return sendMessageWithOptions(request, runtime);
}

